import {
	Sprite,
	Texture
} from "pixi.js";

import Mixin from './utils/Mixin.js';
import DrawBase from './DrawBase.js';

/**
 * image
 *
 * ImageItem
 * 
 * @extends PIXI.Sprite
 * @class
 * @memberof Nice.DrawBase
 * @author iwangcj
 */
class ImageItem extends Sprite {

	constructor(imagepath = "") {
		super();

		this.image = imagepath || "";

	}

	get image() {
		return this._image;
	}

	set image(image) {
		if (image && typeof image === 'string') {
			super.texture = Texture.from(image);
			this._image = image;
		}
	}

 	/**
	 * 获取风格属性
	 * @param {string} key 
	 */
	_getAttrStyle(key) {

        let result = undefined; //未定义
        if ('visible' === key) {
            result = this.visible;
        }

        return result;
    }

	/**
	 * 设置风格属性
	 * @param {string} key 
	 * @param {any} value
	 */
    _setAtterStyle(key, value=undefined) {
        let isOk = true;
        if ('visible' === key) {
            this.visible = value;
        }
        else {
            isOk = false;
        }
        return isOk;
    }


	/**
     * @param {*} key 
     * @param {*} value 
     */
    attrStyle(key, value=undefined) {
        if (undefined != value) {
            return this._setAtterStyle(key, value)
        }
        else {
            return this._getAttrStyle(key);
        }
    }

	/**
     * get/set 属性
     * @param {*} key 
     * @param {*} value 
     */
    attr(key, value) {
        if (undefined != value) {
			let isOk = this.attrBase(key, value);
			!isOk && (isOk = this.attrStyle(key, value));
			return isOk;
        }
        else {
			let result = this.attrBase(key);
			undefined == result && (result = this.attrStyle(key));
            return result;
        }
    }
}

export default Mixin(ImageItem, DrawBase);